/**
 * 描述：生命周期实例管理
 * 作者：彭涛涛
 * 日期：2019年6月24日
 * 版本：0.0.1
 **/
(function(E, KIT, RES) {
  "use strict";
  var __AXIS = null;
  var __URL_ROOT = RES.URL_ROOT + "/mymanage";
  //region  系统通知
  var _getGridSystemMessageFields_ = [{
      title: "内容", name: "attrib_20", frozen: true, width: 250, size: 12
    }, {
      title: "通知时间", name: "attrib_14", width: 100
    }, {
      title: "状态", name: "attrib_15", width: 100
    }, {
      title: "阅读时间", name: "attrib_21", width: 100
    }], _changeState = function(contactids) {
      rapid.post({
        url: __URL_ROOT + "/changeState",
        data: {
          contactids: contactids.toString()
        },
        success: function(result) {
          rapid("#grdSystemMessage").grid().reload();
        }
      });
    },
    _getGridMultiActions_ = function() {
      return [{
        toolbar: true,
        text: "阅读",
        filter: function(item) {
          return item.attrib_15 != "已阅";
        },
        handler: function() {
          _changeState(rapid("#grdSystemMessage").grid().keySelection());
          return true;
        }
      }];
    },
    _initSystemMessageGrid_ = function() {
      rapid("#grdSystemMessage").grid({
        height: "100%",

        addable: false,
        updatable: false,
        removable: false,
        detailed: true,
        rowHeight: "always",

        dataSource: {
          url: __URL_ROOT + "/getSystemMessage"
        },
        pageable: true,
        keyFields: "conflict_id",
        paramFields: ["conflict_id"],
        fields: _getGridSystemMessageFields_,
        multiActions: _getGridMultiActions_(),
        dataview: {
          colSize: 2
        },
        window: {
          size: "xxl"
        }
      });
    },
    _initUiSystemMessage_ = function() {
      var __app = this;
      //查询
      rapid.ui("#txtState").on("change", function() {
        rapid("#grdSystemMessage").grid().load({
          data: {
            attrib_15: this.val()
          }
        });
      });
    };
  //endregion

  //region  开放工作流代办
  var _getGridFields_ = [{
      title: "标题", name: "attrib_02", frozen: true, size: 12, width: 350
    }, {
      title: "发起人", name: "name", width: 100
    }, {
      title: "结束时间", name: "attrib_14", width: 130, align: "center",
      formatter: rapid.date.removeTime
    }],
    _initGrid_ = function() {
      rapid("#grdMyTask").grid({
        height: "100%",

        addable: false,
        updatable: false,
        removable: false,
        detailed: true,
        rowHeight: "always",

        dataSource: {
          url: __URL_ROOT + "/getTasks"
        },
        pageable: true,
        keyFields: "conflict_id",
        paramFields: ["conflict_id"],
        dataview: {
          colSize: 2
        },
        window: {
          size: "default"
        },
        fields: _getGridFields_
      });

    },
    //endregion

    //region生命周期实例代办
    _getGridNodeFields_ = [{
      title: "标题", name: "attrib_01", frozen: true, size: 12, width: 146,
      action: function(e) {

        return this.action({id: "name", text: e.attrib_01});
      }
    }, {
      title: "编号", name: "attrib_03", width: 80
    }, {
      title: "有效截止日期", name: "attrib_14", width: 95, align: "center",
      formatter: rapid.date.removeTime
    }, {
      title: "节点名称", name: "node01", width: 146
    }, {
      title: "节点表单名称", name: "node13", width: 146
    }, {
      title: "节点表单编号", name: "code", width: 80
    }, {
      title: "节点有效截止日期", name: "node14", width: 118, align: "center",
      formatter: rapid.date.removeTime
    }],
    _initGridNode_ = function() {
      rapid("#grdMyExample").grid({
        height: "100%",
        addable: false,
        updatable: false,
        removable: false,
        detailed: true,
        quickView: false,
        dataSource: {
          url: __URL_ROOT + "/getExamples"
        },
        pageable: true,
        keyFields: "conflict_id",
        paramFields: ["row_id", "conflict_id"],
        dataview: {
          colSize: 2
        },
        window: {
          size: "default"
        },
          onname: function() {

        var __code = this.selection()[0].ui().code.val();
            var __nodeid = this.selection()[0].ui().conflict_id.val();
            var node13 = this.selection()[0].ui().node13.val();
        if(rapid.isEmpty(__code)) {
          rapid.info("未获得动态表单，请点击表格刷新按钮再试。");
        } else {
          KIT.openPageTab(RES.URL_ROOT + "/formdata/index?title=" + node13 + "&code=" + __code + "&keyid=" + __nodeid,node13,__nodeid);

        }
      }          ,
        fields: _getGridNodeFields_
      });
    },
    //endregion

    //region动态表单代办
    _initGridForm_ = function() {
      rapid("#grdMyForm").grid({
        height: "100%",
        addable: false,
        updatable: false,
        removable: false,
        detailed: true,
        quickView: false,

        dataSource: {
          url: __URL_ROOT + "/getForms"
        },
        pageable: true,
        keyFields: "conflict_id",
        paramFields: ["row_id", "conflict_id"],
        dataview: {
          colSize: 2
        },
        window: {
          size: "default"
        },
        onname: function() {
          var __code = this.selection()[0].ui().code.val();
          if(rapid.isEmpty(__code)) {
            rapid.info("未获得动态表单，请点击表格刷新按钮再试。");
          } else {
            if(!KIT.openPage("/sysadmin/formdata/index?code=" + __code)) {
              rapid.fail("当前访问方式不正确，未能找到系统菜单。");
              return;
            }
          }
        },
        fields: [{
          title: "名称", name: "name", frozen: true, size: 12, width: 380,
          action: function(e) {
            return this.action({id: "name", text: e.name});
          }
        }, {
          title: "编号", name: "code", width: 80
        }, {
          title: "提交时间", name: "last_upd", width: 130, align: "center",
          formatter: "date:yyyy-MM-dd hh:mm"
        }]
      });

    };
  //endregion

  rapid.MyManage(function() {

    //_initUi_();

    _initUiSystemMessage_();

    _initSystemMessageGrid_();

    // _initGrid_();
    //
     _initGridNode_();

   _initGridForm_();

    rapid("#grdSystemMessage").grid().load();
    // rapid("#grdMyTask").grid().load();
     rapid("#grdMyExample").grid().load();
    rapid("#grdMyForm").grid().load();

  }).init();

})(rapid.html.Element, rapid.kit, rapid.res);